import 'package:flutter/material.dart';
import 'package:node_chat/CustomUI/ButtonCard.dart';
import 'package:node_chat/CustomUI/ContactCard.dart';
import 'package:node_chat/Model/ChatModel.dart';
import 'package:node_chat/screen/CreateGroup.dart';

class SelectContact extends StatefulWidget {
  const SelectContact({
    super.key,
  });

  @override
  State<SelectContact> createState() => _SelectContactState();
}

class _SelectContactState extends State<SelectContact> {
  @override
  Widget build(BuildContext context) {
    List<ChatModel> contacts = [
      ChatModel(
          name: "dev stack",
          icon: "icon",
          status: "a full devloper",
          isGroup: false,
          time: "time",
          select: false,
          currentMessage: "currentMessage",
          id: 1),
      ChatModel(
          name: "dev stack",
          icon: "icon",
          status: "a full devloper",
          isGroup: false,
          time: "time",
          select: false,
          currentMessage: "currentMessage",
          id: 2),
      ChatModel(
          name: "dev stack",
          icon: "icon",
          status: "a full devloper",
          isGroup: false,
          time: "time",
          select: false,
          currentMessage: "currentMessage",
          id: 3),
      ChatModel(
          name: "dev stack",
          icon: "icon",
          status: "a full devloper",
          isGroup: false,
          time: "time",
          select: false,
          currentMessage: "currentMessage",
          id: 4),
    ];

    return Scaffold(
        appBar: AppBar(
          title: const Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                "select Contact",
                style: TextStyle(fontSize: 19, fontWeight: FontWeight.bold),
              ),
              Text(
                "2312312",
                style: TextStyle(fontSize: 13),
              )
            ],
          ),
          actions: [
            IconButton(
              icon: const Icon(
                Icons.search,
                size: 26,
              ),
              onPressed: () {},
            ),
            PopupMenuButton<String>(
              onSelected: (value) {
                print(value);
              },
              itemBuilder: (BuildContext conttext) {
                return [
                  const PopupMenuItem(
                    value: "invite a friend",
                    child: Text("invite a friend"),
                  ),
                  const PopupMenuItem(
                    value: "contacts",
                    child: Text("contacts"),
                  ),
                  const PopupMenuItem(
                    value: "refresh",
                    child: Text("refresh"),
                  ),
                  const PopupMenuItem(
                    value: "help",
                    child: Text("help"),
                  ),
                ];
              },
            )
          ],
        ),
        body: ListView.builder(
            itemCount: contacts.length + 2,
            itemBuilder: (context, index) {
              if (index == 0) {
                return InkWell(
                  onTap: () {
                    Navigator.push(
                        context,
                        MaterialPageRoute(
                            builder: (builder) => const CreateGroup()));
                  },
                  child: const ButtonCard(
                    icon: Icons.group,
                    name: "New group",
                  ),
                );
              } else if (index == 1) {
                return const ButtonCard(
                  icon: Icons.person_add,
                  name: "New contact",
                );
              }
              return ContactCard(
                contact: contacts[index - 2],
              );
            }));
  }
}


// const ButtonCard(
//             icon: Icons.group,
//             name: "new group",
//           ),
//           const ButtonCard(
//             icon: Icons.person_add,
//             name: "new contact",
//           ),